<?php
/**
 * Created SubStr.php.
 * User: 1971229701@qq.com
 * Date: 2020/7/27
 * Time: 17:45
 * Name: Administrator
 */

namespace app\common\helper;


class SubStr
{
    /**
     * 字符串截取替换
     * @param string $type 类型
     * @param null $bank
     * @param null $account 账号
     * @return null|string
     */
    public function subStr($type,$bank = null,$account = null)
    {

        if ($type === 'ALI' && !is_null($account)){   // 手机号截取
            $start = substr($account,0,3);
            $end = substr($account,-4);
            $length = strlen($account) - 7;
            $str = $start.str_repeat('*',$length).$end;
        }elseif ($type === 'AMT' && !is_null($account)){ // 银行卡号截取
            $start = substr($account,0,4);
            $end = substr($account,-4);
            $length = strlen($account) - 8;
            $str = $start.str_repeat('*',$length).$end;
        }else{
            $str = $bank;
        }
        return $str;
    }

    /**
     * 字符串去重
     * @param string $str
     * @return string
     */
    public function strUnique($str = '')
    {
        $str = trim($str,',');
        $arr = explode(',', $str);
        $arr = array_unique($arr);//内置数组去重算法
        $data = implode(',', $arr);
        $data = trim($data,',');//trim — 去除字符串首尾处的空白字符（或者其他字符）,假如不使用，后面会多个逗号
        return $data;
    }
}
